Reallocation

The following describes the reallocation feature in Order Management.

Overview

The reallocation feature allows a warehouse employee to decline a partial or whole consignment and reallocate it to a different warehouse. Order Management supports both manual and auto reallocation. This means that the individual who wants to reallocate a consignment to another warehouse can manually select which other warehouse will be responsible for servicing the consignment or can alternatively, delegate the responsibility of finding the other warehouse by re-running the sourcing for the declined quantity.

Reallocation Consignment Action

In the waiting step ("waitForShipConsignment"/"waitForPickupConsignment") for the consignment process, the consignment can either be cancelled, confirmed, pick/pack or reallocated. The reallocation can be triggered by the UI Controller{....}, where the warehouse employee has the option to do either a manual reallocation to provide the new warehouse, or can leave the new location empty to perform auto reallocation.

The UI Controller populates the DeclineEntries, sets it into the contextParameters of the selected consignmentProcess and triggers the reallocation event for this process. The ReAllocationConsignmentAction extracts the DeclineEntries, and performs the manual/auto (or both) reallocation, based on if the DeclineEntry has a reallocationWarehouse specified or not. As a result of reallocation, the ATP (Available To Promise) also gets updated.

The action starts the consignment processes for the newly created consignments, as a result of the manual reallocation. To fulfill the declined quantities, as a result of auto reallocation, the action sends the reSource event for the associated order, to re-run the sourcing.

Also, the system is expected to trigger different decline action strategies depending on the decline reason selected when declining the consignment entry. This is achieved by providing the action with a map of DeclinedReason and corresponding decline action strategies. Based on the reason for each DeclineEntry, the corresponding DeclineActionStrategy is invoked.

By default, Order Management provides 3 strategies:
  1. DefaultDamagedStockDeclineStrategy: This is mapped to DAMAGED decline reason.
  2. DefaultTimedBanDeclineStrategy: This is mapped to OTHER, TOOBUSY, and STORECLOSED decline reasons.
  3. DefaultOutOfStockDeclineStrategy: This is mapped to OUTOFSTOCK decline reason.

    The 3 above strategies are an extension point for you to implement your own specific logic in case the default logic doesn't fit your business needs.

For more information about consignment, see Consignments.

Decline Action Strategies

A declineActionsMap is a key/value map that is injected into the ReAllocationConsignmentAction. It holds keys as decline reasons and values as the strategies that will be invoked for each reason.

warehousing-spring.xml:

    <bean id="defaultTimedBanDeclineStrategy"
          class="de.hybris.platform.warehousing.allocation.decline.action.impl.DefaultTimedBanDeclineStrategy">
        <property name="sourcingBanService" ref="sourcingBanService"/>
    </bean>
    <bean id="defaultOutOfStockDeclineStrategy"
          class="de.hybris.platform.warehousing.allocation.decline.action.impl.DefaultOutOfStockDeclineStrategy">
        <property name="warehouseStockService" ref="warehouseStockService"/>
        <property name="inventoryEventService" ref="inventoryEventService"/>
    </bean>
    <bean id="defaultDamagedStockDeclineStrategy"
          class="de.hybris.platform.warehousing.allocation.decline.action.impl.DefaultDamagedStockDeclineStrategy">
        <property name="warehouseStockService" ref="warehouseStockService"/>
        <property name="inventoryEventService" ref="inventoryEventService"/>
    </bean>
<alias name="defaultDeclineActionsMap" alias="declineActionsMap"/>
    <util:map id="defaultDeclineActionsMap">
        <entry value-ref="defaultDamagedStockDeclineStrategy">
            <key>
                <util:constant
                        static-field="de.hybris.platform.warehousing.enums.DeclineReason.DAMAGED"/>
            </key>
        </entry>
        <entry value-ref="defaultTimedBanDeclineStrategy">
            <key>
                <util:constant
                        static-field="de.hybris.platform.warehousing.enums.DeclineReason.OTHER"/>
            </key>
        </entry>
        <entry value-ref="defaultOutOfStockDeclineStrategy">
            <key>
                <util:constant
                        static-field="de.hybris.platform.warehousing.enums.DeclineReason.OUTOFSTOCK"/>
            </key>
        </entry>
        <entry value-ref="defaultTimedBanDeclineStrategy">
            <key>
                <util:constant
                        static-field="de.hybris.platform.warehousing.enums.DeclineReason.TOOBUSY"/>
            </key>
        </entry>
        <entry value-ref="defaultTimedBanDeclineStrategy">
            <key>
                <util:constant
                        static-field="de.hybris.platform.warehousing.enums.DeclineReason.STORECLOSED"/>
            </key>
        </entry>
    </util:map>

Decline Action Strategy API

DeclineActionStrategy:

/**
 * Defines decline action strategies
 */
public interface DeclineActionStrategy
{
	void execute(final DeclineEntry declineEntry);
}

DefaultTimedBanDeclineStrategy

When a consignment entry is declined for the reasons TOOBUSY, STORECLOSED, and OTHER, the system acknowledges that the Backoffice employee is swamped with work and they can not continue to serve more orders for a certain period of time. We chose to implement this default strategy to take out the location that was flagged as temporarily unavailable from the sourcing algorithm for a period of time. Therefore, the worker will not receive any more orders at this location for the remainder of time of this introduced ban. ReAllocationConsignmentAction will trigger this strategy for the decline reasons TOOBUSY, STORECLOSED, and OTHER. This strategy will create a sourcingBan and link it to the warehouse where the consignment entry was declined. It will also use the SourcingBanService to create the sourcing ban.

Task Assignment Workflow:

ReAllocationConsignmentAction starts a consignment workflow for a manual reallocation in the method performManualDecline:

ReAllocateConsignmentAction.java
protected void performManualDecline(DeclineEntries manualDeclineEntries)
    {
...
getWarehousingConsignmentWorkflowService().startConsignmentWorkflow(consignment);
    }

As for performAutoDecline there is no need to start the workflow as it will re-source the consignment. It goes through creating a consignment in the allocationService which will create a workflow and assign it to the newly created consignment.

Sourcing Bans:

We maintain a 1 to many relationship between WarehouseModel and SourcingBanModel. The following shows what the sourcing ban service API looks like:

Sourcing Ban Service API:
/**
 *
 *  The service is used create and fetch SourcingBans by warehouses
 *
 */
public interface SourcingBanService
{
	/**
	 * creates Sourcing Ban
	 * @param warehouseModel warehouse that we want to ban
	 * @return SourcingBanModel linked to the passed Warehouse, this ban will expire in 1 day by default
	 */
	SourcingBanModel createSourcingBan(WarehouseModel warehouseModel);
	/**
	 * gets SourcingBan by passing Warehouse
	 * @param warehouseModels </warehouseModel> collection of warehouse that we want to get bans for
	 * @return collection of SourcingBans that for warehouses that is active within configurable period (1 day by default)
	 */
	Collection<SourcingBanModel> getSourcingBan(Collection<WarehouseModel> warehouseModels);
}

The default banned period is set to 1 day, and can be changed by providing the property below:

project.properties of Warehousing:
#number of days to ban a warehouse after decline a consignment entry from it for the reason "Too Busy"
warehousing.ban.toobusy.days=1

Declined Location Filter:

We need to act on the SourcingBan that was created by the DefaultTimedBanDeclineStrategy. In order to achieve this, a DeclineLocationFilter is added to the list of locationFilters to ban a warehouse that is marked as unavailable for a configurable period of time.

declinedLocationfilter.java:
public class DeclinedLocationFilter extends AbstractBaseSourcingLocationFilter
{
    private static Logger LOGGER = LoggerFactory.getLogger(DeclinedLocationFilter.class);
    private SourcingBanService sourcingBanService;
    @Override
    public Collection<WarehouseModel> applyFilter(final AbstractOrderModel order, final Set<WarehouseModel> locations)
    {
        LOGGER.debug("finding what locations to exclude.");
        Collection<SourcingBanModel> existingBans = getSourcingBanService().getSourcingBan(locations);
        Collection<WarehouseModel> locationsToExclude = existingBans.stream().map(p -> p.getWarehouse()).collect(Collectors
                .toList());
        LOGGER.debug("Filter '" + getClass().getSimpleName() + "' excluded '" + locationsToExclude.size() + "' warehouses.");
        return locationsToExclude;
    }

This location filter will use the SourcingBanService to query for existing bans on sourcing locations and exclude the locations that have bans.

DefaultOutOfStockDeclineStrategy

When a Backoffice employee flags an item as out of stock on their decline screen, the system interprets this as an error in the availability for this item in this location. Normally, the worker will go to a different page in the Backoffice application to correct this availability and sets it to the real number that they actually have. This new strategy will allow the worker to save time by doing this action right from the decline screen. By declining an item for out of stock reason, the system will reduce the availability for this declined item on this location to 0.

ReAllocationConsignmentAction will trigger this strategy for the decline reason OutOfStock. This strategy creates a shrinkage event with a quantity that is equal to the local ATP for this declined item in the warehouse, so that local ATP for this item in this location will be reduced to 0.

DefaultOutOfStockDeclineStrategy:
public class DefaultOutOfStockDeclineStrategy implements DeclineActionStrategy
{
    private static Logger LOGGER = LoggerFactory.getLogger(DefaultOutOfStockDeclineStrategy.class);
 
    @Override
    public void execute(final DeclineEntry declineEntry)
    {
        final long quantityToShrink = getWarehouseStockService().getStockLevelForProductAndWarehouse(declineEntry
                .getConsignmentEntry().getOrderEntry()
                .getProduct(), declineEntry.getConsignmentEntry().getConsignment().getWarehouse());
         
        // only create Shrinkage event if atp quantity is more than 0
        if (quantityToShrink.longValue() > 0 ){
        inventoryEventService.createShrinkageEvent(declineEntry.getConsignmentEntry(), quantityToShrink);
        LOGGER.debug("Out of Stock Strategy is being invoked, Shrinkage event is being created for the amount: " +
                quantityToShrink);
    }

DefaultDamagedStockDeclineStrategy

ReAllocationConsignmentAction will trigger this strategy for the decline reason Damaged. This strategy creates a Wastage event with a quantity that is equal to the local ATP for this declined item in the warehouse, so that local ATP for this item in this location will be reduced to 0. Future work on this strategy will ask the warehouse worker to input the amount they want to report as wasted rather than creating a wastage amount for the whole inventory.

DefaultDamagedStockDeclineStrategy:
/**
 * Strategy to apply when the decline reason for a consignment entry is {@link de.hybris.platform.warehousing.enums
 * .DeclineReason#DAMAGED}.
 */
public class DefaultDamagedStockDeclineStrategy implements DeclineActionStrategy
{
    private static Logger LOGGER = LoggerFactory.getLogger(DefaultDamagedStockDeclineStrategy.class);
    private InventoryEventService inventoryEventService;
    private WarehouseStockService warehouseStockService;
    @Override
    public void execute(final DeclineEntry declineEntry)
    {
        final Long quantityToWaste = getWarehouseStockService().getStockLevelForProductAndWarehouse(declineEntry
                .getConsignmentEntry().getOrderEntry()
                .getProduct(), declineEntry.getConsignmentEntry().getConsignment().getWarehouse());
        // only create Wastage event if atp quantity is more than 0
        if (quantityToWaste.longValue() > 0 ){
        inventoryEventService.createWastageEvent(declineEntry.getConsignmentEntry(), quantityToWaste);
        LOGGER.debug("Damaged Strategy is being invoked, Wastage event is being created for the amount: " +
                    quantityToWaste);
        }
    }