In-order delivery in ZigBee is not guaranteed, as one message may have taken a longer route than another, or may have been subject to more end-to-end retries than the other (even if the source is the same), causing a second packet to arrive earlier than the first. Duplicate filtering is also not guaranteed (as it may be that the message itself arrives at the destination but the ACK doesn’t arrive in time to preclude the next end-to-end retry attempt), so the application may receive the same packet (up to 3 times) in the IncomingMessageHandler if APS_RETRY option is enabled in the unicast options.
To help account for these anomalies, the APS layer includes a sequence number (apsFrame->sequence) that the application can check on the incoming APS frame (and also in the MessageSentHandler at the sender
side) to know which packets were received in what order, which are duplicates, and when sent packets were ACKed properly.
If sending a number of related unicasts between a pair of devices where duplicate filtering and in-order delivery is important, an application may wish to employ fragmentation, which delivers a set of related packets together as a single bundle. See the fragmentation utility library description in the EmberZNet API Guide for more information, as well as the fragment*.h code in app/util/zigbee-framework.