# Expected stock in availability

In some business scenarios, stock should be available for sale before it has arrived at a facility or has been produced. fulfillmenttools supports two approaches depending on how precisely the expected stock is known at the time of sale.

If a concrete purchase order exists and the delivery date is known, expected stock can be tracked and made available for sale. Reservations can be made on this stock and are automatically shifted to real stock once the delivery has arrived. This article will cover this scenario.

If the delivery date or quantity is not yet known, a purchase order with a large quantity is created to avoid stock limits on incoming customer orders. Once the purchase order is placed or the production schedule is defined, the quantity is adjusted to reflect the actual amount. For more information, see the [Demand-based replenishment article](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/expected-stock-in-availability/demand-driven-replenishment).

## Selling and managing expected stock

In some cases, stock should be available for sale before it has even arrived at the site or has been produced. This means that expected stock needs to be tracked and communicated to shop systems. It's also necessary that reservations can be made on expected stock.

### Use case example

A company is selling gift items online and in retail stores. As a special service, the company offers to send the gift directly to the recipient on the day of the birthday. As the delivery date often lies far in the future, it should be possible to take expected stock into account when ordering. Furthermore, some of the gift baskets contain perishable goods. As the company only wants to sell items up to 30 days before their expiration date, this attribute must also be taken into account when customers place orders and reservations are made.

### Implementation in fulfillmenttools

{% stepper %}
{% step %}
**Create listings**

In most set-ups, listings should already be created for all products that are managed via fulfillmenttools' systems. Still, make sure that a listing exists for each product whose expected stocks should be considered. If goods are perishable and/or should only be available for a certain time frame, [stock properties](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/stock-properties) and/or [stockAvailableUntil](https://docs.fulfillmenttools.com/documentation/by-pillar/listing#stock-available-until) must be configured. For this use the [facilities listings REST API endpoint](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#put-/api/facilities/-facilityId-/listings).
{% endstep %}

{% step %}
**Create purchase order**

Create a purchase order for all items that have already been (re-)ordered. After the purchase order has been created, an expected stock is automatically created for each position in `requestedItems`. If [stock properties](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/stock-properties) such as expiry date or batch number are already known at the time of the order placement they can be defined as well. For this use the [purchase order REST API endpoint](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/purchaseorders).

{% hint style="warning" %}
Don't create purchase orders with `requestedDate.type` "ASAP". As we expect these deliveries to arrive as soon as possible, there is no exact date that our systems can use to check the potential availability of these stocks for incoming orders.
{% endhint %}
{% endstep %}

{% step %}
**Query checkout options endpoints for shop availability**

Query one of the [checkout options endpoints](https://docs.fulfillmenttools.com/documentation/availability-and-promising#checkout-options) to get the future availability for a specific delivery date or time period. In the future availability, all stock is included that:

* Is [pickable and accessible](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/inventory-traits)
* Has already arrived at the site at the start of the picking
* Doesn't exceed its [availableUntil date](https://docs.fulfillmenttools.com/documentation/by-pillar/listing#stock-available-until) until the (desired) delivery date

Before using the [delivery/earliest REST API](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/promises/checkoutoptions/delivery/earliest) or the [delivery/timeperiod REST API](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/promises/checkoutoptions/delivery/timeperiod) endpoint, the transit times in the [carrier country service mapping](https://docs.fulfillmenttools.com/documentation/store-operations/carrier-management/carrier-features-and-requirements#country-service-mapping) for the requested carrier(s) must be configured.

{% hint style="warning" %}
Expected stocks are only considered in the checkout options endpoint if the `desiredDeliveryTime` is specified in the request and the mode for `reservationPreferences` is set to "ALAP" (as late as possible).
{% endhint %}

Use the [checkout options REST API endpoints](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/promises/checkoutoptions/collect/earliest).

**Example:**

Request availability for a gift item in the store in Cologne for the delivery date 14 September 2024:

1. **Request:** `POST /api/promises/checkoutoptions/delivery/timepoint​`

* `desiredDeliveryDate`: "2024-09-14"
* `tenantArticleId`: gift-set-01​
* `facilityRef`: facility-CGN​
  * `latestPickingStart` for Cologne: "2024-09-10"

{% hint style="info" %}
If the latest possible picking start for a certain delivery date in a facility is not known, it can be requested via the [checkout options REST API endpoint](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/promises/checkoutoptions). Systems then calculate the `latestPickingStart` based on [cut-off time](https://docs.fulfillmenttools.com/documentation/store-operations/carrier-management/carrier-features-and-requirements#carrier-capacity-management) of carriers and [fulfillment process buffer](https://docs.fulfillmenttools.com/documentation/by-pillar/store-operations/picking/pick-job-target-time).​
{% endhint %}

2. **Availability check:**

After the request has been made, an availability check is performed which validates if the expected stock fulfills all necessary criteria to be considered for the (potential) order. ​

* Is `desiredDeliveryDate` before the `availableUntil` date?​ Items should not have expired until they have reached the customer.
* Is `latestPickingStart` after the requested date of stock​? Items must have arrived in the facility before they can be picked.

3. **Response:**

The response returns all stock in the requested facility that is currently available and will not expire until the desired delivery date plus all expected stock that fulfills the criteria of the availability check.

* Available: 30
  {% endstep %}

{% step %}
**Make reservation**

If an item should already be reserved but has not been ordered yet (for example, a customer placed it in the shopping cart), the [delivery promise REST API endpoint](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/promises/deliverypromise) can be used.\
If an order was placed and the item should be reserved, the [order REST API endpoint](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/orders) can be used.

See the [Reservations article](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/reservations) for more information.

{% hint style="warning" %}
Expected stocks are only considered in promising and order routing if the `desiredDeliveryTime` is specified in the request and the mode for `reservationPreferences` is set to `ALAP` (as late as possible).
{% endhint %}
{% endstep %}

{% step %}
**Manage reservations on expected stocks**

Reservations on expected stock can be monitored via the [Stock overview](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/broken-reference) in Backoffice.

See the [Stock availability article](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/stock-availability) for more information on expected stock.

<figure><img src="https://content.gitbook.com/content/Lrrr5jgTsDuR38gNJIrm/blobs/oqxENQEgpVAq222hoH5G/Expected%20stock%20-%20release%20notes.jpg" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Create stock after delivery has arrived**

If the delivery of the ordered products has arrived or the production was finished, a receipt needs to be added to the inbound process of the purchase order to create stock. Use the [purchase order REST API endpoint](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#get-/api/purchaseorders/-purchaseOrderId-) to query the respective `inboundProcessRef` if it is not stored in your systems.

After the stock was created in the facility, reservations are shifted from expected stock to "real" stock. When shifting reservations, an available stock in the facility is chosen, considering the [running sequence](https://docs.fulfillmenttools.com/documentation/by-pillar/storage-locations-and-zones#running-sequences-on-storage-locations) (if defined). This means the reservation is not necessarily made on the exact item that has arrived in the delivery.
{% endstep %}
{% endstepper %}

### FAQs

<details>

<summary><strong>What happens if the requested date for a delivery changes?</strong></summary>

If it is known that a delivery will arrive later than planned, the `requestedDate` in the `purchaseOrder` needs to be patched for the correct date. After the purchase order has been updated, our systems check whether reservations on the respective expected stocks can still be fulfilled. If the delivery arrives too late to be considered for a reservation, the reservation is shifted to an alternative stock. If there is no alternative stock available, the reservation is still tracked and will be shifted to a stock as soon as some stock becomes available.

</details>

<details>

<summary><strong>What happens if the supplier can only deliver fewer goods than ordered?</strong></summary>

If it is know that there will be less items in the delivery than ordered, the `requestedItems` in the `purchaseOrder` need to be patched for the correct items and quantities. After the purchase order has been updated, our systems check whether reservations on the respective expected stocks can still be fulfilled. If a reservation on the purchase order cannot be fulfilled anymore, the reservation is shifted to an alternative stock. If there is no alternative stock available, the reservation is still tracked and will be shifted to a stock as soon as some stock becomes available.

</details>

<details>

<summary><strong>What happens if part of the delivery is missing or defective?</strong></summary>

After a delivery has arrived and a [receipt was added to the inbound process](#id-6.-create-stock-after-delivery-has-arrived), reservations are shifted from expected to "real" stock. If there is not enough stock available in the facility due to some items in the delivery being missing or defective, the reservations will still be tracked and shifted to a stock as soon as some stock becomes available.

</details>

<details>

<summary><strong>What happens if the delivery is delayed?</strong></summary>

If a delivery is delayed, it is no longer considered for new reservations. Existing reservations on the expected stocks are kept until the purchase order has been cancelled. Therefore, we advise users to update the requestedDate or cancel the purchaseOrder as soon as it is known that the delivery will be delayed.

</details>
