Order Utils
Intended Audience:
Technical User
Author:
Holger Lierse
Changed on:
20 Sept 2025
Overview
The `OrderUtils`
class in the `util-sourcing`
is a utility class that provides order-specific utilities for sourcing operations. It handles order-related sourcing operations including fulfillment creation, fulfillment type determination, and order item management.
Key points
- Order-Specific Operations: Handles order-related sourcing operations.
- Fulfillment Creation: Creates fulfillment records based on sourcing plans.
- Fulfillment Type Management: Sets fulfillment types based on business rules.
- Order Item Management: Manages order items and their allocation to fulfillments.
Core Methods
`createFulfilments()`
Creates fulfillments from a `SourcingPlan`
, allocating order items to locations and assigning fulfillment types.
1// Create fulfillments from the sourcing plan
2List<Fulfilment> createdFulfilments = OrderUtils.createFulfilments(
3 context,
4 sourcingContext,
5 plan.getFulfilments()
6);
`fillFulfilmentType()`
Determines and assigns a fulfillment type for each fulfillment based on the Sourcing Context characteristics such as location type and delivery method.
1// Set fulfillment types based on business rules
2OrderUtils.fillFulfilmentType(sourcingContext, fulfilments);
`itemsMinusFulfilments()`
Subtracts the item quantities in a set of fulfillments from a list of order items. This can be used to determine the remaining order items after a set of proposed (but not yet created) fulfillments.
1// Get unfulfilled items
2List<OrderItem> unfulfilledItems = SourcingUtils.getUnfulfilledItems(context);
3
4// Find partial fulfillment
5Optional<Fulfilment> partialFulfilmentOpt = SourcingUtils.findHighestValuePartialFulfilment(
6 locationAndPositions,
7 unfulfilledItems,
8 Collections.emptySet() // No excluded locations
9);
10
11// Calculate remaining items after partial fulfillment
12if (partialFulfilmentOpt.isPresent()) {
13 Fulfilment partialFulfilment = partialFulfilmentOpt.get();
14 List<OrderItem> remainingItems = OrderUtils.itemsMinusFulfilments(
15 unfulfilledItems,
16 Arrays.asList(partialFulfilment)
17 );
18}