RahalCorporate
PoliciesConcepts

Rule Matching

How policy rules are prioritized and matched to bookings

Rule Matching

When a user makes a booking, the system evaluates it against the policy's rules. Understanding how rules are matched helps you create effective policies.

The Matching Process

1. Get user's effective policy

2. Filter rules that match the booking criteria

3. Sort matching rules by budget threshold (descending)

4. Evaluate each rule for violations

5. First rule with violations → determines action
   No violations in any rule → ALLOW

Step 1: Policy Resolution

First, the system determines which policy applies to the user:

  1. User-specific policy (if assigned and within effective dates)
  2. Role-based policy (if assigned to user's role)
  3. Company default policy (fallback)

See Policy Hierarchy for details.

Step 2: Rule Filtering (Location Matching)

The system filters rules to find all that match the booking's location criteria.

Flight Rule Matching

A flight rule matches if ALL of the following conditions are true:

ConditionLogic
OriginRule origin city matches, OR rule origin country matches (if no city specified), OR rule has no origin (wildcard)
DestinationRule destination city matches, OR rule destination country matches (if no city specified), OR rule has no destination (wildcard)
InternationalRule isInternational matches, OR rule has no isInternational setting (wildcard)

Matching hierarchy for origin/destination:

1. City specified → must match exactly
2. Country specified (no city) → must match country
3. Neither specified (null) → matches any (wildcard)

Hotel Rule Matching

A hotel rule matches if the location matches:

ConditionLogic
LocationRule city matches, OR rule country matches (if no city specified), OR rule has no location (wildcard)

Null values in rules act as wildcards. A rule with no origin/destination restrictions matches all flights. A rule with no location restrictions matches all hotels.

Step 3: Sorting Matched Rules

After filtering, matching rules are sorted by budget threshold in descending order (highest budget first).

For flights, this considers duration-based tiers:

  • The system calculates the effective budget for the flight's duration
  • Rules are sorted by this duration-adjusted budget

Why descending order?

The system evaluates from highest budget to lowest. The first rule where the booking exceeds the limit triggers a violation. This ensures the most permissive matching rule that still has violations is selected.

Step 4: Violation Evaluation

Each matching rule is evaluated in order until a violation is found.

Flight Violations

Violation TypeTriggered When
PRICEFlight price exceeds rule's max budget (considering duration tiers)
CABIN_CLASSSelected cabin class not in allowed list (considering duration tiers)
STOPSNumber of stops exceeds rule's max stops
ADVANCE_BOOKINGBooking made fewer than required days before departure

Hotel Violations

Violation TypeTriggered When
PRICENightly rate exceeds rule's max price
STAR_RATINGHotel star rating not in allowed list
NIGHTSStay length exceeds rule's max nights
ADVANCE_BOOKINGBooking made fewer than required days before check-in

Step 5: Action Determination

ScenarioResult
Violations foundUse rule's action if specified, otherwise use policy default action
No violations in any matching ruleReturn ALLOW
No rules match the bookingUse policy default action (no violations)

Duration Tier Evaluation

For flight rules with duration tiers, the system:

  1. Gets the flight's duration in hours
  2. Finds the matching tier range
  3. Uses that tier's budget/cabin limits for evaluation

Budget Tier Example

Min HoursMax HoursBudget
03$450
37$650
7null$1,000
  • 2-hour flight at $500: Uses 0-3hr tier ($450) → Price violation
  • 5-hour flight at $600: Uses 3-7hr tier ($650) → No violation
  • 10-hour flight at $900: Uses 7+hr tier ($1,000) → No violation

Cabin Tier Example

Min HoursMax HoursAllowed Classes
05Economy
58Economy, Premium Economy
8nullEconomy, Premium Economy, Business
  • 4-hour flight, Business class: Uses 0-5hr tier (Economy only) → Cabin violation
  • 6-hour flight, Premium Economy: Uses 5-8hr tier → No violation
  • 10-hour flight, Business class: Uses 8+hr tier → No violation

If flight duration doesn't match any tier, the rule's base budget/cabin settings are used.

Complete Example

Policy rules (after matching a Baghdad → Dubai flight):

RuleBudgetCabinPriority
Baghdad → Dubai$500Economy10
Iraq → UAE$700Economy, Premium20
All international$1,000Economy, Premium75

Booking: Baghdad → Dubai, $600, Premium Economy

  1. Filter: All 3 rules match (Baghdad is in Iraq, Dubai is in UAE, flight is international)
  2. Sort by budget (desc): $1,000, $700, $500
  3. Evaluate $1,000 rule: $600 < $1,000 ✅, Premium allowed ✅ → No violations
  4. Evaluate $700 rule: $600 < $700 ✅, Premium allowed ✅ → No violations
  5. Evaluate $500 rule: $600 > $500 ❌ → Price violation, Premium not allowed ❌ → Cabin violation
  6. Result: Violations found on $500 rule → Use that rule's action (or policy default)

The most specific rule (Baghdad → Dubai) triggers because it has the lowest budget. Even though less restrictive rules also match, the system finds violations against the strictest applicable limit.

Priority vs. Budget Sorting

Priority (set in the dashboard) controls:

  • Display order in the UI
  • Which rule is considered "primary" when multiple match

Budget sorting (during evaluation) ensures:

  • The most restrictive applicable limit is enforced
  • Violations are detected at the appropriate threshold

In practice, specific routes (Priority 10) typically have lower budgets than catch-all rules (Priority 100), so the two orderings often align.

Best Practices

Always Create a Catch-All Rule

Without a catch-all rule (matching "All flights" or "All hotels"), bookings that don't match any specific rule will use the policy's default action with no violations — effectively allowing them.

Route: All flights
Budget: $2,000
Cabin: Economy, Premium Economy
Action: (use policy default)

Order Budgets from Specific to General

RouteBudgetRationale
Baghdad → Dubai$500Known short route
Iraq → Gulf$700Regional travel
International$1,000Long-haul
All flights$1,500Catch-all

Use Duration Tiers for Long-Haul Flexibility

Don't set a single budget that's too low for long flights or too high for short flights:

Base: $500
Tiers:
  0-4 hours: $450
  4-8 hours: $700
  8+ hours: $1,200

Test Your Rules

Use the policy preview feature to verify rule matching:

  1. Go to Policies → Assignments
  2. Select a user
  3. Enter sample booking details
  4. See which rule matches and what violations would occur

On this page