Skip to Main Content
MintSoft Ideas Portal
Status New
Categories Order Management
Created by Guest
Created on May 8, 2026

Order Rules - Day of the week for RequiredDespatchDate

No description provided
Current Problem

Similar to the OrderDateDayofWeek, add condition that checks day of week for RequiredDespatchDate. This would allow e.g. changing the courier service based on the despatch day (so if you are despatching on a Friday, you send with a Saturday service).


Honestly quite chocked this does not come out-of-the-box in Mintsoft Shipping Mgmt.

Idea to resolve Problem See text.
  • Attach files
  • Guest
    May 8, 2026

    Here is the code for it


    // =============================================================================
    // Mintsoft Order Rules – New Condition Fields
    //
    // Feature Request: RequiredDespatchDateDayOfWeek & RequiredDespatchDateTimeOfDay
    //
    // These two condition types are direct equivalents of the existing:
    // - OrderDateDayOfWeek (string operators, e.g. "Monday", "Friday")
    // - OrderDateTimeOfDay (decimal operators, e.g. GreaterThan 14.0 = after 2pm)
    //
    // ...but derived from RequiredDespatchDate instead of OrderDate.
    //
    // Follows the same patterns already established in the codebase.
    // =============================================================================

    using System;

    namespace Mintsoft.OrderRules.Conditions
    {
    /// <summary>
    /// Evaluates the day of the week of an order's RequiredDespatchDate.
    ///
    /// Mirrors the behaviour of OrderDateDayOfWeek but uses RequiredDespatchDate
    /// as the source field.
    ///
    /// Supported operators: all string operators except Empty / IsNotEmpty.
    /// - Equals e.g. "Monday"
    /// - NotEqual e.g. "Saturday"
    /// - Contains e.g. "on" matches Monday, Wednesday, etc.
    /// - DoesNotContain
    /// - StartsWith e.g. "T" matches Tuesday, Thursday
    /// - DoesNotStartWith
    ///
    /// Param value: a day name string (case-insensitive), e.g. "Friday"
    /// </summary>
    public class RequiredDespatchDateDayOfWeekCondition : IOrderRuleCondition
    {
    public string ConditionType => "RequiredDespatchDateDayOfWeek";

        public bool Evaluate(Order order, string operatorType, string paramValue)
    {
    if (order.RequiredDespatchDate == null)
    return false;

    // Derive the day-of-week name from RequiredDespatchDate
    string dayOfWeek = order.RequiredDespatchDate.Value.DayOfWeek.ToString(); // e.g. "Friday"

    return StringConditionEvaluator.Evaluate(dayOfWeek, operatorType, paramValue);
    }
    }

    /// <summary>
    /// Evaluates the time of day of an order's RequiredDespatchDate, expressed
    /// as a decimal hour (e.g. 14.5 = 14:30, 9.0 = 09:00).
    ///
    /// Mirrors the behaviour of OrderDateTimeOfDay but uses RequiredDespatchDate
    /// as the source field.
    ///
    /// Supported operators: all decimal operators.
    /// - GreaterThan e.g. 14.0 → despatch time is after 2pm
    /// - LessThan e.g. 12.0 → despatch time is before noon
    /// - EqualsOrGreaterThan e.g. 9.0 → despatch time is 9am or later
    /// - EqualsOrLessThan e.g. 17.0 → despatch time is 5pm or earlier
    /// - Equals / NotEqual e.g. 8.0 → despatch time is exactly 8am
    ///
    /// Param value: a decimal number as a string, e.g. "14.5"
    ///
    /// Note: If RequiredDespatchDate has no time component (i.e. it is a date-only
    /// value, midnight), the evaluated time will be 0.0. This matches the
    /// behaviour of OrderDateTimeOfDay for orders where no time was recorded.
    /// </summary>
    public class RequiredDespatchDateTimeOfDayCondition : IOrderRuleCondition
    {
    public string ConditionType => "RequiredDespatchDateTimeOfDay";

    public bool Evaluate(Order order, string operatorType, string paramValue)
    {
    if (order.RequiredDespatchDate == null)
    return false;

    if (!decimal.TryParse(paramValue, out decimal threshold))
    return false;

    // Convert time portion to decimal hours, matching OrderDateTimeOfDay convention
    DateTime despatchDate = order.RequiredDespatchDate.Value;
    decimal timeOfDay = despatchDate.Hour + (despatchDate.Minute / 60m);

    return DecimalConditionEvaluator.Evaluate(timeOfDay, operatorType, threshold);
    }
    }

    }

    // =============================================================================
    // Supporting infrastructure (shown for completeness / clarity).
    // These are assumed to already exist in the codebase, mirroring what
    // OrderDateDayOfWeek and OrderDateTimeOfDay already use.
    // Included here so the feature request is self-contained and unambiguous.
    // =============================================================================

    namespace Mintsoft.OrderRules.Conditions
    {
    /// <summary>
    /// Evaluates string-based condition operators.
    /// Already used by: OrderDateDayOfWeek, CourierService, PostCode, etc.
    /// </summary>
    public static class StringConditionEvaluator
    {
    public static bool Evaluate(string fieldValue, string operatorType, string paramValue)
    {
    if (fieldValue == null)
    return false;

            switch (operatorType)
    {
    case "Equals":
    return string.Equals(fieldValue, paramValue, StringComparison.OrdinalIgnoreCase);

    case "NotEqual":
    return !string.Equals(fieldValue, paramValue, StringComparison.OrdinalIgnoreCase);

    case "Contains":
    return fieldValue.IndexOf(paramValue, StringComparison.OrdinalIgnoreCase) >= 0;

    case "DoesNotContain":
    return fieldValue.IndexOf(paramValue, StringComparison.OrdinalIgnoreCase) < 0;

    case "StartsWith":
    return fieldValue.StartsWith(paramValue, StringComparison.OrdinalIgnoreCase);

    case "DoesNotStartWith":
    return !fieldValue.StartsWith(paramValue, StringComparison.OrdinalIgnoreCase);

    // Empty / IsNotEmpty are explicitly NOT supported for these condition types,
    // matching the behaviour of OrderDateDayOfWeek.
    default:
    return false;
    }
    }
    }

    /// <summary>
    /// Evaluates decimal-based condition operators.
    /// Already used by: OrderDateTimeOfDay, OrderValue, TotalWeight, etc.
    /// </summary>
    public static class DecimalConditionEvaluator
    {
    public static bool Evaluate(decimal fieldValue, string operatorType, decimal threshold)
    {
    switch (operatorType)
    {
    case "GreaterThan":
    return fieldValue > threshold;

    case "LessThan":
    return fieldValue < threshold;

    case "EqualsOrGreaterThan":
    return fieldValue >= threshold;

    case "EqualsOrLessThan":
    return fieldValue <= threshold;

    case "Equals":
    return fieldValue == threshold;

    case "NotEqual":
    return fieldValue != threshold;

    default:
    return false;
    }
    }
    }

    // -------------------------------------------------------------------------
    // Condition registry registration
    //
    // Wherever the existing conditions are registered (likely a factory,
    // dictionary, or switch statement), add these two entries alongside
    // the existing OrderDateDayOfWeek and OrderDateTimeOfDay registrations:
    // -------------------------------------------------------------------------

    public static class OrderRuleConditionRegistry
    {
    // Add these two lines next to wherever OrderDateDayOfWeek and
    // OrderDateTimeOfDay are registered:
    //
    // { "RequiredDespatchDateDayOfWeek", new RequiredDespatchDateDayOfWeekCondition() },
    // { "RequiredDespatchDateTimeOfDay", new RequiredDespatchDateTimeOfDayCondition() },
    }

    }

    // =============================================================================
    // Usage examples
    // =============================================================================
    //
    // EXAMPLE 1: Change courier to "SATURDAY_SERVICE" if RequiredDespatchDate
    // falls on a Friday (so it ships Friday, arrives Saturday).
    //
    // Condition Field: RequiredDespatchDateDayOfWeek
    // Operator: Equals
    // Value: Friday
    // Action: ChangeCourierService → SATURDAY_SERVICE
    //
    //
    // EXAMPLE 2: Change courier to "NEXT_DAY_AM" if RequiredDespatchDate is
    // before noon (e.g. urgent morning despatch).
    //
    // Condition Field: RequiredDespatchDateTimeOfDay
    // Operator: LessThan
    // Value: 12.0
    // Action: ChangeCourierService → NEXT_DAY_AM
    //
    //
    // EXAMPLE 3: Combined AND rule – Friday AND after 2pm gets an express service.
    //
    // Condition Type: AND
    // Condition 1: RequiredDespatchDateDayOfWeek Equals Friday
    // Condition 2: RequiredDespatchDateTimeOfDay GreaterThan 14.0
    // Action: ChangeCourierService → EXPRESS_FRIDAY_PM
    //
    // =============================================================================