Skip to main content

Warehouse routing

WarehouseRouterService.determineWarehousesForOrder is the routing decision used when an order is held and when it is planned into fulfillment orders. The file comment says an older assignWarehouseToOrder used to pin order.warehouseId and made this splitter dead. This service is the one that runs now.

Rules that the code states​

  • Active warehouses are loaded with deletedAt: null, ordered by priority descending, then createdAt.
  • StockOwnership.EXTERNAL is excluded from automatic routing. The comment says OMS pick and pack does not run in FBA or 3PL mirrors. An explicit order.warehouseId still wins, including an FBA assignment.
  • If order.warehouseId points at an active warehouse, every line is assigned there. Shortfall is backordered at that warehouse, not sent to another site. EXTERNAL is allowed on this explicit assignment.
  • Otherwise routing uses owned warehouses. WarehouseChannelLocation rows with contributesStock limit the set. No mapping rows, or a filter that matches nothing, falls back to every owned warehouse so a bad mapping cannot leave the order unroutable.
  • Sort: TenantSetting.preferredWarehouseId first, then higher priority.
  • Default unstockedFulfillmentPolicy when the tenant setting is missing is PASS_THROUGH.

How a line is split​

  1. If one prioritized warehouse can cover every line (shortfallAt is 0), the whole order stays there.
  2. Otherwise each line takes stock from warehouses with quantityAvailable greater than 0, largest availability first.
  3. Quantity nobody can cover is assigned to the primary warehouse. Primary is preferredWarehouseId when that warehouse is in the routable list, otherwise the first warehouse after the sort. The remainder is quantityBackordered unless the line is pass-through or hold.

isLineUnstockedHold is true when policy is HOLD_AS_EXCEPTION and the line has no product, or the product manages stock and has no stock record. Products with manageStock false are not a hold.

isPassThroughOrHold is true for a missing product when policy is PASS_THROUGH or HOLD_AS_EXCEPTION, for manageStock false, and for a managed product with no stock record under those two policies. In that case the remainder is still assigned to the primary warehouse but quantityBackordered is 0.

What this is not​

Setting a warehouse on the order later is Move an order. That cancels existing fulfillment orders. Routing here is the first assignment.

No HTTP route calls this service directly. It runs inside fulfillment planning.