How to set an order as shipped programmatically from an external ERP system?

To mark an order as shipped you can create a shipment document for it.
How is «Submit Shipment» implemented?