A MoonBit freight billing rule engine for parcel logistics.
moon check --target all
moon test --target all
moon run cmd/main///|
test {
let rule = standard_rule()
let parcel = parcel_dim(width_cm=42, height_cm=30, depth_cm=24, weight_g=2600)
let result = quote(rule, parcel, "regional", Money::yuan(300))
inspect(result.summary(), content="billable=5040g total=CNY 61.03 lines=5")
}moon run cmd/maintypes.mbt public domain types
money*.mbt exact money and rounding operations
parcel*.mbt dimensional weight and parcel profiling
rules.mbt / audit*.mbt tariff construction and validation
engine.mbt quote and manifest calculation
discounts.mbt / taxes.mbt adjustments and tax basis
routing.mbt origin/destination lane resolution
catalog*.mbt operational weight-band tables
manifest_analytics.mbt manifest-level operational metrics
tariff_composition.mbt candidate selection and decision traces
settlement_*.mbt invoice, payment, and reconciliation workflows
sla_calendar.mbt business-day and service-window deadlines
customs_engine.mbt duty, insurance, and declared-value totals
bulk_pipeline.mbt deterministic bulk-job transitions
route_planner.mbt capacity-aware shortest-path planning
manifest_validation.mbt duplicate, value, weight, and zone checks
audit_chain.mbt tamper-evident event history
service_promise.mbt delivery promise and breach classification
cmd/main runnable example
benchmarks deterministic performance smoke benchmarkmoon run benchmarksmoon fmt --check
moon check --deny-warn --target all
moon info
moon test --deny-warn --target all
moon test --deny-warn --target native --enable-coverage
moon coverage report -f summaryfn BusinessCalendar::working_days_between(self : BusinessCalendar, start_day : Int, end_day : Int) -> Intpub enum ChargeLine {
Base(weight_g~ : Int, Money)
Additional(units~ : Int, Money)
Zone(zone~ : String, multiplier_bp~ : Int, Money)
Remote(zone~ : String, Money)
Overweight(limit_g~ : Int, Money)
Oversize(limit_cm~ : Int, Money)
Fuel(percent_bp~ : Int, Money)
Insurance(percent_bp~ : Int, declared_value~ : Money, Money)
Minimum(Money)
} derive(Eq, ToJson, Debug)pub struct ConfigDiagnostic {
code : String
severity : DiagnosticSeverity
field : String
message : String
} derive(Eq, ToJson, Debug)pub struct ManifestIssue {
tracking_no : String
kind : ManifestIssueKind
detail : String
} derive(Eq, ToJson, Debug)pub struct ManifestValidation {
valid : Bool
issues : Array[ManifestIssue]
accepted : Int
} derive(Eq, ToJson, Debug)pub struct ServicePromise {
pickup_day : Int
delivery_day : Int
latest_day : Int
status : PromiseStatus
} derive(Eq, ToJson, Debug)pub struct ValidationSummary {
errors : Int
warnings : Int
infos : Int
diagnostics : Array[ConfigDiagnostic]
} derive(Eq, ToJson, Debug)fn billing_rule(volumetric_divisor~ : Int, first_weight_limit_g~ : Int, first_weight_rate~ : Money, additional_weight_unit_g~ : Int, additional_weight_rate~ : Money, min_charge~ : Money, zones~ : Array[ZoneRate], surcharge~ : SurchargePolicy) -> BillingRulefn business_calendar(weekend_days : Array[Int], holidays : Array[Int], cutoff_hour : Int) -> BusinessCalendarfn choose_tariff(candidates : Array[TariffCandidate], parcel : ParcelDim, zone : String, declared_value : Money, day : Int) -> DecisionTracefn customs_document(hs_code : String, description : String, declared_value : Money, origin : String, restricted : Bool) -> CustomsDocumentfn customs_line(code : String, declared_value : Money, duty_bp : Int, insurance_bp : Int) -> CustomsLinefn make_service_promise(calendar : BusinessCalendar, pickup_day : Int, pickup_hour : Int, transit_days : Int, buffer_days : Int, actual_delivery_day : Int) -> ServicePromisefn manifest_item(tracking_no : String, zone : String, parcel : ParcelDim, declared_value : Money) -> ManifestItemfn reconcile_lines(expected : Array[SettlementLine], actual : Array[SettlementLine], tolerance : Money) -> ReconciliationReportfn route_edge(from : String, to : String, distance_km : Int, transit_days : Int, capacity_g : Int, zone : String) -> RouteEdgefn route_leg(origin : String, destination : String, zone : String, days : Int, capacity_g : Int) -> RouteLegfn service_deadline(calendar : BusinessCalendar, start_day : Int, start_hour : Int, transit_days : Int, buffer_days : Int) -> Intfn service_window(service : String, minimum_days : Int, maximum_days : Int, cutoff_hour : Int) -> ServiceWindowfn surcharge_policy(overweight_limit_g~ : Int, overweight_fee~ : Money, oversize_limit_cm~ : Int, oversize_fee~ : Money, fuel_percent_bp~ : Int, insurance_percent_bp~ : Int) -> SurchargePolicyfn tariff_candidate(id : String, priority : Int, effective_from : Int, effective_to : Int, predicates : Array[TariffPredicate], charge : Money) -> TariffCandidateInstall
Download zipA MoonBit freight billing rule engine for parcel logistics.