Sourcing Service - Technical Overview

The following gives a technical overview of the sourcing service in Order Management.

The sourcing service is defined by interfaces, enabling you to evaluate the best way to source orders using various sourcing strategies.

Overview

The service evaluates the best way to source orders using defined sourcing strategies and fitness evaluators. The results collected during sourcing will determine the number of consignments that need to be created.

Class Diagram

The class diagram provides a general overview of the classes and interfaces for the sourcing service.

Sourcing Service API

The sourcing service determines if an order can be sourced. It also identifies the optimal way of creating consignments to fulfill an order.

SourcingService.java:

public interface SourcingService
{
	SourcingResults sourceOrder(AbstractOrderModel order);
}

Steps

The sections below describe the steps executed by the sourcing service.

1. Filter Locations

The sourcing service uses Sourcing Filters to find a minimal working subset of locations to use for sourcing. By default, 3 sourcing filters will be applied in the following order:

  1. Filter locations based on the delivery countries.
  2. Filter locations based on the pickup address.
  3. Filter locations based on the stock availability of the product.

2. Group Order Entries

The sourcing service will group all order entries with common attributes together. Order entries belonging to different groups cannot belong to the same consignment. This process is called Order Entry Grouping.

OrderEntryGroupingService.java:

public interface OrderEntryGroupingService
{
    /**
     * Split an order into a groups of order entries based on a collection of matchers.
     *
     * @param order
     *           - the abstract order entry model
     * @param matchers
     *           - the order entry matchers
     * @return a set of order entry groups; never <tt>null</tt>
     */
    Set<OrderEntryGroup> splitOrderByMatchers(final AbstractOrderModel order, final Collection<OrderEntryMatcher<?>> matchers);
 
    /**
     * Split an existing collection of order entry groups into smaller groups using a single matcher.
     *
     * @param groups
     *           - the collection of order entry groups
     * @param matcher
     *           - the order entry matcher
     * @return a set of order entry groups; never <tt>null</tt>
     */
    Set<OrderEntryGroup> splitGroupsByMatcher(final Set<OrderEntryGroup> groups, final OrderEntryMatcher<?> matcher);
 
    /**
     * Split a single order entry group into multiple groups using a single matcher.
     *
     * @param group
     *           - the order entry group
     * @param matcher
     *           - the order entry matcher
     * @return a set of order entry groups; never <tt>null</tt>
     */
    Set<OrderEntryGroup> splitGroupByMatcher(final OrderEntryGroup group, final OrderEntryMatcher<?> matcher);
}

3. Create Sourcing Context

Sourcing will require some order entry groups information as well as some information from the various filtered point of services that can be used during sourcing. This information will be aggregated into a sourcing context POJO. The sourcing context will also hold the current sourcing results and allow each sourcing strategy to update this result. Every order entry group will have an associated sourcing context, which are created using the SourcingContextFactory.

SourcingContextFactory.java:

public interface SourcingContextFactory
{
	public Collection<SourcingContext> create(final Collection<OrderEntryGroup> groups, final Collection<PointOfServiceModel> locations) 
	throws IllegalArgumentException;
}

4. Find Sourcing Strategies

The sourcing service calls the SourcingStrategyService to find the sourcing strategies. Sourcing Strategy Mappers are used to decide which sourcing strategies should be applied for a given sourcing context.

SourcingStrategyService.java:

public interface SourcingStrategyService
{
	List<SourcingStrategy> getStrategies(final SourcingContext context, Collection<SourcingStrategyMapper> mappers);
	
	List<SourcingStrategy> getDefaultStrategies();
}

5. Apply Sourcing Strategy

Iterate through the list of Sourcing Strategies found to find the best way to source the order.

SourcingStrategy.java:

public interface SourcingStrategy
{
	public void source(final SourcingContext sourcingContext);
 
	Boolean isTerminal();
}

6. Create/Aggregate Sourcing Results

As a last step, we create/aggregate sourcing results using SourcingResultFactory.

SourcingResultFactory.java:

public interface SourcingResultFactory
{
	/**
	 * Create a sourcing result.
	 *
	 * @param orderEntry       the abstract order entry model
	 * @param sourcingLocation the location from where to source the product.
	 * @param quantity         the quantity to source for this product and this location.
	 * @return the sourcing result
	 */
	public SourcingResult create(final AbstractOrderEntryModel orderEntry, final SourcingLocation sourcingLocation,
			final Long quantity);
	
	/**
	 * Create a sourcing result where all order entries are sourced from the given sourcingLocation and using the
	 * quantity specified by {@link AbstractOrderEntryModel#getQuantity()}.
	 *
	 * @param orderEntries
	 *           - the collection of abstract order entry model
	 * @param sourcingLocation
	 *           - the location from where to source the product
	 * @return the sourcing result
	 */
	public SourcingResult create(final Collection<AbstractOrderEntryModel> orderEntries, final SourcingLocation sourcingLocation);
	
	/**
	 * Create a sourcing result where all order entries are sourced from the given sourcingLocation and using the
	 * quantity specified in the allocation map.
	 *
	 * @param allocation
	 *           - the map of abstract order entry model and the quantity allocated
	 * @param sourcingLocation
	 *           - the location from where to source the product
	 * @return the sourcing result
	 */
	public SourcingResult create(final Map<AbstractOrderEntryModel, Long> allocation, final SourcingLocation sourcingLocation);
	
	/**
	 * Create a single sourcing result from a collection of sourcing results.
	 *
	 * @param results - the collection of sourcing results; should not be <tt>null</tt>
	 * @return the merged sourcing result; never <tt>null</tt>
	 */
	public SourcingResults create(Collection<SourcingResults> results);
}