# Shipping methods

Shipping methods are used to provide customers with different delivery options.

Shipping methods are defined by currency and can be restricted to an active [market](https://docs.commercelayer.io/core-api-reference/markets) (in the latter case the currency is inherited by the market's price list).

* Set the `shipping_category` relationship if you want the shipping method to be available only if the items to be shipped belong to a specified [shipping category](https://docs.commercelayer.io/core-api-reference/shipping_categories).
* Set the `shipping_zone` relationship if you want the shipping method to be available only if the shipping address belongs to a specified [shipping zone](https://docs.commercelayer.io/core-api-reference/shipping_zones).
* Set the `stock_location` relationship if you want the shipping method to be available only if the items are shipped from a specific stock location.
* Specify a value for the `tax_code` attribute if you want to use a custom tax code for your shipments tax calculation (currently supported by [Avalara](https://docs.commercelayer.io/core-api-reference/avalara_accounts) only).
* Specify a value for the `min_weight` and/or `max_weight` attributes (to do that also a `unit_of_weight` must be defined) if you want the shipping method to be available only if the total weight of the items to be shipped falls within those values.

{% hint style="info" %}
The total weight of the shipment is automatically calculated from the single weights of the items included (i.e. the `weight` attribute of the [SKUs](https://docs.commercelayer.io/core-api-reference/skus/object) to be shipped).
{% endhint %}

## Default shipping method

A shipping method that is not already associated with any market, stock location, shipping category, or shipping zone can be set as the [default shipping method](https://docs.commercelayer.io/core-api-reference/markets#default-shipping-method) for one or more markets. To do that:

* [Create](https://docs.commercelayer.io/core-api-reference/shipping_methods/create) a new shipping method and keep it as more generic as possible by setting the required parameters only:
  * `name`
  * `currency_code`
  * `price_amount_cents`
* Now you can set that shipping method as the default for one or more markets as long as they are associated with a price list in the same currency.

In this case, [shipping weight tiers](#shipping-weight-tiers) (if any) will be ignored.

## Shipping method cost

### Free over amount

Each shipping method can have a price and can be free over a specific order's total amount. Set the `use_subtotal` attribute to `true` (default is `false`) if you want to compare the free over amount with the order's subtotal and exclude other discount calculations (if any).

### Shipping weight tiers

Set the proper value for the `scheme` attribute (default is `flat`) to define how you want to manage the shipping method cost:

* `flat` — the shipping method has a fixed price (equal to the value of the `price_amount_cents` attribute).
* `weight_tiered` — the shipping method price is [tiered](https://docs.commercelayer.io/core-api-reference/shipping_method_tiers) based on the total weight of the items included in the shipment (a maximum of **5** tiers for each shipping method is currently supported). See [shipping weight tiers](https://docs.commercelayer.io/core-api-reference/shipping_weight_tiers) to learn more.
* `external` — the shipping method price is fetched [from an external service](https://app.gitbook.com/s/-LgByaSP8eKjad-MIuHE/external-resources/external-shipping-costs) which handles the custom calculation, overriding the `price_amount_cents` set at creation time (remember to specify the `external_prices_url` when creating or updating the shipping method).

{% hint style="info" %}
If a `free_over_amount` was specified, it applies regardless of the tier. If a `min_weight` and/or `max_weight` value for the shipping method's availability was specified, only the tiers between those values will be considered.
{% endhint %}

### Shipping cost cut-off

If you want to apply a [custom shipping cost policy](https://docs.commercelayer.io/core-api-reference/markets#market-specific-shipping-costs-policy) (e.g. charging your customers with one single shipping cost for the whole order) you can set to 0 the unit amount of some of the line items of type `shipments` that are created when a shipping method is associated with an order's shipments. To do that, leverage the dedicated attribute at the market level.

<details>

<summary>Data model</summary>

Check the related [ER diagram](https://commercelayer.io/docs/data-model/shipping-zones-and-methods) and explore the flowchart that illustrates how the shipping method resource relates to the other API entities.

</details>

<details>

<summary>How-to</summary>

Check the related [guide](https://app.gitbook.com/s/-Lk-ezuDClaMavTqnRi0/placing-orders/checkout/selecting-a-shipping-method) to learn how to let a user choose one of the available shipping methods during the checkout. Learn how to manage the shipping methods cost [via external services](https://app.gitbook.com/s/-LgByaSP8eKjad-MIuHE/external-resources/external-shipping-costs).

</details>
