Performs the actual business logic of the command.
Behavior:
In the following description, the terms allOrderItems, remergeOrderItems, mergeOrderItems, checkOrderItems, allocateOrderItems, backOrderItems, and reverseOrderItems. They refer to the OrderItems specified by the caller as input parameters. These parameters are set using setAllOrderItems, setRemergeOrderItems, setMergeOrderItems, setCheckOrderItems, setAllocateOrderItems, setBackorderOrderItems, and setReverseOrderItems methods, respectively.
- Throughout this invocation, unlock an OrderItem's Order if its quantity or FulfillmentCenter is changed.
- To prevent changes to OrderItems that have already been released for fulfillment. Throughout this invocation, OrderItems in remergeOrderItems, mergeOrderItems, checkOrderItems, allocateOrderItems, backOrderItems, and reverseOrderItems are ignored. Unless their InventoryStatus attribute is one of "NALC", "BO", "FUL", or "ALLC".
- Any allocations of existing or expected inventory associated with the allocateOrderItems, backorderOrderItems, or reverseOrderItems are released by calling the DeallocateExistingInventory or calling DeallocateExpectedInventory task command respectively. Estimated availability times and shipping offsets and other allocation information are removed from those OrderItems. Except the FulfillmentCenters are left unchanged (that way they can be considered by GetEligibleFulfillmentCenters).
- For each currently unallocated OrderItem in mergeOrderItems determine what other unallocated OrderItems in allOrderItems exist with identical values for all columns except for ORDERITEMS_ID, QUANTITY, CORRELATIONGROUP, LASTCREATE, LASTUPDATE, information calculated by PrepareOrder (such as SHIPCHARGE, SHIPTAXAMOUNT, TAXAMOUNT, TOTALADJUSTMENT, and TOTALPRODUCT), and information specific to the allocation status such as FulfillmentCenter (unless it has been overridden in the prepareFlags attribute), availableQuantity, ALLOCATIONGROUP, LastAllocUpdate, EstAvailTime, PromisedAvailTime, ShippingOffset, NeededQuantity, AllocQuantity, AllocFFMC_ID, and AllocAddress_ID, and merge them into the same OrderItem by deleting the others and adding their quantity amounts to that OrderItem. Estimated availability times and shipping offsets and other allocation information such as availableQuantity (but not FulfillmentCenters overridden in the prepareFlags attribute) are removed from merged OrderItems. The CORRELATIONGROUP attributes of the merged OrderItems are set to their own OrderItemID.
- For each remaining unallocated OrderItem in remergeOrderItems determine what other unallocated OrderItems in allOrderItems exist with identical values for CORRELATIONGROUP. As well as all the other columns defined in the previous step (the mergeOrderItems case). If the CORRELATIONGROUP of one of those so determined OrderItems is the OrderItem's OrderItemID, then merge the other so determined OrderItems into that OrderItem. Otherwise, merge the so determined OrderItems into one of those so determined OrderItems. The order item should also appear in remergeOrderItems by deleting the others and adding their quantity amounts to that OrderItem. Estimated availability times and shipping offsets and other allocation information such as availableQuantity (but not FulfillmentCenters overridden in the prepareFlags attribute) are removed from merged OrderItems. The CORRELATIONGROUP attributes of the merged OrderItems are left unchanged.
- Call GetEligibleFulfillmentCenters to determine a list of eligible FulfillmentCenters for each remaining unallocated OrderItem in checkOrderItems, allocateOrderItems, and backorderOrderItems.
- Call CheckInventoryAvailability passing it the list of remaining unallocated OrderItems in checkOrderItems and their lists of eligible FulfillmentCenters. Update the estimated availability times and shipping offsets of the unallocated OrderItems with the information returned by CheckInventoryAvailability. The results and reason codes from this call are made available to an error JSP, in a way backward compatible with WCS V5.1.
- For each remaining unallocated OrderItem in allocateOrderItems, attempt to allocate it using its list of eligible FulfillmentCenters. Use the following algorithm for each OrderItem:
- Set the current strategy to zero.
- Set the previous strategy to something different and set the previous OrderItem to null.
- While the current OrderItem is unallocated or backordered. And either it is not the previous OrderItem or the current strategy is different than the previous strategy:
- Set the previous strategy to the current strategy and set the previous OrderItem to the current OrderItem.
- Call AllocateExistingInventory specifying the current OrderItem, its list of eligible FulfillmentCenters, and the current strategy.
- Set the current strategy to the nextStrategy (returned from AllocateExistingInventory).
- If the current OrderItem is partially allocated, and the unallocated part is greater than or equal to StoreItem.MinQtyForSplit. Create a new (unallocated) OrderItem to hold the unallocated part, and make it the current OrderItem. (Make sure to adjust the Quantity for both the old and the new OrderItem so that the ratio between OrderItems.Quantity and OrderItems.NeededQuantity remains the same. To avoid round off errors caused by discrepancies between CatEntShip.QuantityMultiple and BaseItem.QuantityMultiple. If the OrderItem has a CatEntry with a CatEntShip record, then multiply the resulting Quantity by CatEntShip.NominalQuantity. And round to the nearest multiple of CatEntShip.QuantityMultiple, and divide by CatEntShip.NominalQuantity. If the OrderItem has a CatEntry but no CatEntShip record, CatEntShip.NominalQuantity and CatEntShip.QuantityMultiple are assumed to be 1, and CatEntShip.QuantityMeasure is assumed to be 'C62'.)
- Otherwise, if the current OrderItem is partially allocated, and the unallocated part is less than StoreItem.MinQtyForSplit, reverse the partial allocation and leave the OrderItem unallocated.
The above algorithm allows the AllocateInventory task command to control the splitting of OrderItems. While giving control of the details of inventory allocation decisions to the AllocateExistingInventory task command. For example, the inventory allocation decision may be whether or not partial allocation is performed.
When an OrderItem is split, the new OrderItem contains the same information. Except for the ORDERITEMS_ID, QUANTITY, and information specific to the allocation such as FFMCENTER_ID, estimated availability time and shipping offset.
- For each remaining unallocated OrderItem in backorderOrderItems (and any created in the above step by splitting them). Attempt to backorder it using its list of eligible FulfillmentCenters, or its existing overridden FulfillmentCenter. This will involve making calls to AllocateExpectedInventory. Otherwise it should behave the same as specified in the previous step.
- For any allocations associated with remaining OrderItems in reverseOrderItems. And for any allocations for OrderItems created (in the above steps) while allocating any of those OrderItems. These allocations are released (by calling DeallocateExistingInventory or DeallocateExpectedInventory as appropriate). For their estimated availability time and shipping offset and other allocation information, such as FulfillmentCenter. They are left in the OrderItem allowing it to be displayed as how the OrderItems would have been allocated had they not been reversed.