# Offer a specific shipping method for free in a specific country

This rule discounts a shipping method for all the orders in a given country. The country code of the order is checked and, if it matches the desired country, a 100% percentage discount is applied to the shipment line items (if any) whose shipment has a shipping method that matches the provided ID.

The example below is based on the following reference JSONs. Once the rules are evaluated against the resource payload, the outcomes show if and how the conditions are matched and the related actions applied.

{% tabs %}
{% tab title="Rules" %}

```json
{
  "rules": [
    {
      "name": "Free express shipment for US orders",
      "conditions": [
        {
          "field": "order.country_code",
          "matcher": "eq",
          "value": "US"
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "order.line_items.shipment.shipping_method.id",
          "value": 1.0,
          "identifier": "bEegQFyxNw"
        }
      ]
    }
  ]
} 
```

{% endtab %}

{% tab title="Order" %}

```json
{
  "order": {
    "id": "wJZYhBXaWL",
    "country_code": "US",
    "line_items": [
      {
        "id": "fdgXdRsaKo",
        "quantity": 1,
        "unit_amount_cents": 14500
      },
      {
        "id": "vRrYtpaaKv",
        "quantity": 1,
        "unit_amount_cents": 1200,
        "shipment": {
          "id": "eNdLCKWxly",
          "shipping_method": {
            "id": "bEegQFyxNw"
          }
        }
      },
      {
        "id": "vgnYtBqqJk",
        "quantity": 2,
        "unit_amount_cents": 9500
      },
      {
        "id": "ybmetWzzYN",
        "quantity": 1,
        "unit_amount_cents": 4000,
        "shipment": {
          "id": "YVNXCjjWdY",
          "shipping_method": {
            "id": "DEqjzFGqOn"
          }
        }
      }
    ]
  }
}
```

{% endtab %}

{% tab title="Outcomes" %}

```json
[
  {
    "id": "4417633c-8759-438d-823b-a6708ac47192",
    "name": "Free express shipment for US orders",
    "priority": 0,
    "match": true,
    "conditions_logic": "and",
    "conditions": [
      {
        "field": "order.country_code",
        "matcher": "eq",
        "value": "US",
        "group": "1d731a42-864b-459b-ac01-f6a4b293e1a4",
        "match": true,
        "matches": [
          {
            "order": "wJZYhBXaWL",
            "group": "1d731a42-864b-459b-ac01-f6a4b293e1a4"
          }
        ],
        "scope": "any"
      }
    ],
    "actions": [
      {
        "resources": [
          {
            "resource_type": "shipping_methods",
            "id": "bEegQFyxNw",
            "group": null,
            "quantity": 1,
            "value": 1.0,
            "action_type": "percentage"
          }
        ]
      }
    ]
  }
]
```

{% endtab %}
{% endtabs %}

## Rules breakdown

The desired results can be achieved with a single rule.

#### Conditions

The only condition in the rule checks if the order's `country_code` is equal to `US`. This means the rule will only apply if the order is placed from the United States.

#### Actions

The only action in the rule applies a 100% percentage discount to the order's shipment line items that are associated with the shipping method that should be free of charge. The shipment line item eligible for the discount is detected via a selector on the ID of the shipping method (`bEegQFyxNw`).

## Resource payload analysis

The provided payload contains an order placed from the US that has 4 line items: 2 products whose delivery is split into 2 shipments. For one of the shipments (`eNdLCKWxly`, associated with the line item `vRrYtpaaKv`) the shipping method that should be discounted has been selected.

## Outcomes check

The outcomes reflect the evaluation of the rules against the resource payload. Since the order is placed from the US, the rule matches successfully (`match` is `true`) and the order ID is listed in the `matches` array. The action is applied to the identified resource (i.e. the shipping method with ID `bEegQFyxNw`) with the decimal value of `1.0` corresponding to a full percentage discount.

## Conclusion

The rule matches the provided payload. Consequently, the shipment identified as eligible for the discount will have its shipping cost zeroed.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.commercelayer.io/rules-engine/use-cases/promotions/free-shipping-method-by-country.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
