The following SCXML strategy routes an interaction to one of two agents based on a statistic. It requests the statistic value first, waits for this value to become available using a special state called delay, and then uses this value for routing.
<scxml version="1.0" xmlns="http://www.w3.org/2005/07/scxml"
xmlns:queue="www.genesyslab.com/modules/queue"
xmlns:dialog="www.genesyslab.com/modules/dialog"
initial="initial">
<state id="initial">
<transition event="interaction.added" target="statistics"/>
</state>
<state id="statistics">
<onentry>
<script>
var t1 = _genesys.stat.sData('az@.A', 'StatTimeInReadyState');
var t2 = _genesys.stat.sData('bz@.A', 'StatTimeInReadyState');
</script>
</onentry>
<transition target="delay"/>
</state>
<state id="delay">
<onentry>
<send event="'delay'" target="_sessionID" targettype="'scxml'" delay="'2s'"/>
</onentry>
<transition event="delay" target="routing"/>
</state>
<state id="routing">
<onentry>
<queue:submit orderstat="'StatTimeInReadyState'" ordertype="'max'"
priority="5" timeout="20">
<queue:targets type="agent">
<queue:target name="'a_0001'"/>
<queue:target name="'a_0003'"/>
</queue:targets>
</queue:submit>
</onentry>
<transition event="queue.submit.done" target="exit">
<log expr="'DONE'"/>
<log expr="_event.data.targetselected"/>
</transition>
<transition event="error.queue.submit" target="error"/>
</state>
<final id="exit"/>
<final id="error"/>
</scxml>