How Sourcing Utilities work
Author:
Holger Lierse
Changed on:
7 July 2026
Overview
The articles below will walk you through the Sourcing Utilities (`util-sourcing`), designed to simplify implementing complex sourcing logic and reduce repetitive code.PrerequisitesBefore diving in, make sure you have:- A basic understanding of the Utility Bundles and Sourcing Utilities
- Familiarity with writing Rules using the Rules SDK
- Completed the Getting Started with the Utility Bundles guide
Sourcing Utilities Overview
Author:
Holger Lierse
Changed on:
7 July 2026
Overview
The`util-sourcing` library is a comprehensive collection of utility functions designed to minimize the overhead and complexity of writing sourcing logic in your Fluent Commerce rules.PrerequisitesThese articles assumes you're familiar with:- Java
- Maven
- JUnit
Key points
- Sourcing Orchestration (
`SourcingUtils`): Orchestrates the sourcing process and provides helper methods to load a Sourcing Profile - Context Management (
`SourcingContextUtils`): Loads and manages Sourcing Context - Order Helper (
`OrderUtils`): Performs order-specific operations such as fulfillment creation - Location-Based Optimization (
`LocationUtils`): Provides location-based helpers including distance calculations and caching - Fulfillment Options Support (
`FulfilmentOptionsUtils`): Creates fulfillment plans with available quantity tracking and ETA calculation - Sourcing Conditions and Criteria Management: Provides functions, registration, and execution logic for tailoring Sourcing Strategies to the specific needs of customers
Value Proposition
- Eliminate Manual Sourcing: Pre-built utility methods handle complex inventory allocation and location selection logic
- Faster Implementation: Common sourcing patterns are abstracted into reusable, tested components
- Reduced Complexity: Standardized approaches prevent common sourcing errors and edge cases
- Extensibility: Custom sourcing strategies can be easily implemented.
- Consistent Patterns: Enforce best practices across your sourcing rule implementations
Explanation through an Example
Let's walk through a simple real-world scenario to understand how Sourcing Utilities work in practice.Imagine you're running an online store that receives an order for:- 2x Gaming Laptops (high-value items)
- 3x Wireless Mice (medium-value items)
- 1x Gaming Headset (high-value item)
- Main Warehouse (New Jersey) - Has all items in stock
- Local Store (Manhattan) - Has laptops and mice, but no headset
- Regional DC (Boston) - Has all items but higher shipping costs
How Sourcing Utilities Help
What Happens Behind the Scenes
- Inventory Analysis: System checks real-time inventory at all locations
- Distance Calculation: Calculates delivery times and costs for each location
- Strategy Evaluation: Applies business rules (proximity, cost, speed)
- Optimization: Finds the best combination of locations to fulfil the order
Related content
Sourcing Utils
Authors:
Holger Lierse, Kirill Gaiduk
Changed on:
7 Aug 2026
Overview
The`SourcingUtils` class in the `util-sourcing` bundle is the main utility class that orchestrates the entire sourcing process within a rule. It provides core helper methods such as loading a sourcing profile, initializing the sourcing context, and executing the sourcing logic configured in the profile. Each stage supports multiple customization points.Key points
- Main Orchestrator: Central utility class that coordinates all sourcing operations from a rule
- Strategy Evaluation: Evaluates and applies sourcing strategies based on business rules
- Plan Generation: Generates sourcing plans for order fulfillment
- Chunk Loading: Locations are evaluated in incremental chunks to support large sourcing networks. An early availability check skips expensive permutation search when the order cannot be fully sourced from the available stock
- Multi-Attempt Sourcing:
`getPlanFinder`provides a single entry point for primary and fallback sourcing, generating multiple ranked plans without reloading data
Core Methods
`getPlanFinder()`
The preferred single entry point for running primary or fallback sourcing from the same parameters object. Returns a `SourcingPlanFinder` that exposes:`nextFullPlan()`for primary-strategy sourcing`nextFallbackPlan()`for fallback-strategy sourcing
`findPlanBasedOnStrategies()`
Finds the best sourcing plan for an order based on sourcing strategies defined in a sourcing profile.Location evaluation uses a `ChunkLoadingPlanFinder` that loads locations in incremental chunks sized proportionally to the order's item count. - A single-location search is run after each chunk
- A multi-split search runs across the full evaluated set if no single-location plan is found
- An early availability check is performed before entering permutation search - if any item cannot be covered by the combined quantities across candidate locations, permutation search is skipped
`getBasedOnStrategiesPlanFinder()`
Returns a `SourcingPlanFinder` configured for primary sourcing strategies.`findPlanBasedOnStrategies(SourcingExecutionParameters)` is equivalent to `getBasedOnStrategiesPlanFinder(sourcingExecutionParameters).nextPlan()`.Use this when you need to call `findPlanForAllItems` multiple times without reloading sourcing data from scratch - for example, when generating a ranked list of fulfillment plans.`findPlanBasedOnFallbackStrategies()`
Finds the sourcing plan for unfulfilled items using fallback sourcing strategies when no primary strategy fully satisfies the sourcing request.- Only one fallback strategy is used, specifically the first that satisfies the sourcing conditions
- Supports partial sourcing, where fulfillments may not completely satisfy the order
- Location ratings are recalculated after each allocation iteration using remaining unfulfilled items, ensuring each location selection reflects actual demand at that point in the iteration
`getBasedOnFallbackStrategiesPlanFinder()`
Returns a `SourcingPlanFinder` configured for fallback sourcing strategies.`findPlanBasedOnFallbackStrategies(SourcingExecutionParameters)` is equivalent to `getBasedOnFallbackStrategiesPlanFinder(sourcingExecutionParameters).nextPlan()`.Wrap the returned finder (for example, for multi-attempt location exclusion) before calling `findPartialFulfilmentPlan` in a loop.`buildRejectedFulfilment()`
Builds a rejected fulfillment for all remaining unfulfilled items in the sourcing context.Supporting Methods
`findPlanForAllItems()`
This helper method is used by the `findPlanBasedOnStrategies` method to identify a plan for an order based on the sourcing strategies. It ranks candidate locations using the provided sourcing criteria, and searches for the best combination of locations that can cover the full order within the allowed split limit. Fewer-location plans are always preferred.Before entering permutation search, an early availability check sums available quantities for each required item across all candidate locations. If any item cannot be covered, permutation search is skipped. If no valid combination exists, it returns an empty plan.`findHighestValuePartialFulfilment()`
This helper method is used by the `findPlanBasedOnFallbackStrategies` method to find the highest-value partial fulfillment. It filters out excluded locations, compares each candidate's rating based on the remaining unfulfilled items at that iteration, and checks whether the location can cover at least part of the remaining items. The method returns the best fulfillment found or none if no positive-value option exists.`findPartialFulfilmentPlan()`
Builds a greedy partial fulfillment plan by repeatedly calling `findHighestValuePartialFulfilment` until the `maxSplit` limit is reached or all unfulfilled items are covered. Location ratings are recalculated after each allocation iteration.Use `getBasedOnFallbackStrategiesPlanFinder` to obtain a pre-loaded `SourcingPlanFinder`, then wrap it (for example, for multi-attempt location exclusion) before calling `findPartialFulfilmentPlan` in a loop.`loadPositions()`
Loads virtual positions for sourcing operations. This method is used by both core methods (`findPlanForAllItems` and `findPlanBasedOnFallbackStrategies`) to load inventory.`loadSourcingProfile()`
Loads the sourcing profile for the current context.`getUnfulfilledItems()`
Computes outstanding order items after accounting for allocated but non-rejected quantities.`getNetworkRef()`
Gets the network reference from a sourcing profile or strategy.`getVirtualCatalogueRef()`
Gets the virtual catalog reference from a sourcing profile or strategy.`getMaxSplit()`
Gets the maximum split value from a sourcing profile or strategy.Related content
Sourcing Context Utils
Author:
Holger Lierse
Changed on:
17 Sept 2025
Overview
`SourcingContextUtils` in the `util-sourcing` is a utility class for managing sourcing context and data loading operations. It provides methods to create and populate sourcing contexts with order details, unfulfilled items, and supporting data required for sourcing decisions.Key points
- Context Management: Creates and manages Sourcing Context for the sourcing process.
- Data Loading: Handles loading of order, item and required information.
Core Methods
`loadSourcingContext()`
Loads and creates a Sourcing Context with all necessary information such as order details, unfulfilled items, and supporting data required for sourcing decisions.Related content
Order Utils
Authors:
Holger Lierse, Kirill Gaiduk
Changed on:
13 Aug 2026
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. - Each
`FulfilmentItem`includes an`availableQty`field that records the available quantity at the sourcing location at the time of plan generation - Fulfillment
`refs`are assigned deterministically (`{orderId}-{fulfilmentChoiceId}-{index}`) - derived from the`SourcingContext`Id (e.g., order Id), fulfillment choice Id, and a consecutive index starting from the number of already existing fulfillments. This ensures that two sourcing processes running concurrently for the same fulfillments produce identical refs, preventing duplicate fulfillment creation
`fillFulfilmentType()`
Determines and assigns a fulfillment type for each fulfillment based on the Sourcing Context characteristics such as location type and delivery method. `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.Related content
Location Utils
Author:
Holger Lierse
Changed on:
17 Sept 2025
Overview
The`LocationUtils` class in the `util-sourcing` is a utility class that provides utilities for location-based sourcing decisions. It handles location-specific sourcing logic including distance calculations, location availability checks, and provide location-based caching optimization.Key points
- Location-Based Decisions: Handles location-specific sourcing logic.
- Distance Calculations: Calculates distances between locations for proximity-based sourcing.
- Location Availability: Checks if locations are active and available for sourcing.
- Caching Optimization: Provides location-based caching optimization.
Core Methods
`getLocationByRef()`
Loads a single Location by provided reference, with caching for performance.`getLocationsInNetwork()`
Load all the locations in a network with caching for performance.`getLocationsInNetworks()`
Loads all locations that belong to the provided networks.`distanceInMetres()`
Calculate distance between two points in latitude and longitude using the Haversine formula.Related content
Fulfillment Options Utils
Author:
Kirill Gaiduk
Changed on:
9 July 2026
Overview
The`FulfilmentOptionsUtils` class in the `util-sourcing` library creates `FulfilmentPlan` records for Fulfillment Options from a `SourcingPlan`. It captures the proposed fulfillment options, available quantities, and optional ETA values, helping rules present calculated sourcing outcomes without recreating fulfillment-plan mapping logic.Key points
- Fulfillment Plan Creation: Persists a
`SourcingPlan`as a`FulfilmentPlan`under the fulfillment option entity - ETA Calculation: Accepts an optional
`EtaCalculator`to calculate and set ETA on the plan and on each individual fulfillment. When no`EtaCalculator`is provided, ETA fields are omitted - Available Quantity: Each
`FulfilmentItem`in the plan records the available quantity at the sourcing location at the time of plan generation
Core Methods
`createFulfilmentPlan()`
Persists a `SourcingPlan` as a `FulfilmentPlan` under the fulfillment option entity.- Returns early without action if
`context`,`plan`, or`sourcingContext`is`null`, or if the plan contains no fulfillments - Each item includes
`productRef`,`requestedQuantity`, and`availableQuantity` - If an
`EtaCalculator`is provided, ETA is calculated and set for the plan and for each fulfillment separately