Need help on XDS framework ax 2012

Problem Description:

As per our requirement following will be setup.
Distributor = Company (legal entity) (A distributor can have many branches )
Branches = site
Under a particular company there will be users which belongs to a branches and should not be able to see the data that belongs to other branches.

We will use XDS framework as mentioned in the link below
http://msdn.microsoft.com/EN-US/library/hh272121.aspx

§ For a company we need to create a security policy and create a query (ex: select * from primary_table where site=1)

which will filter the records (analogous to RLS in ax 2009).

§ The query will be assigned to the security policy which will work for a particular role.

§ Now suppose a company has 10 branches, we will create 10 security policies.

§ Each policy will be assigned a role and thus the policy will be applicable to only that role.

§ User is also mapped with a role thus filtering will be done for the user as per his/her branch.

§ Now we will use XDS framework and add constrained tables in the security policy thus the filtering will be applied throughout all modules in dynamics ax.

§ PS : Mapping need to be done for user and the site he/she belongs to in user info table.

Now the issue is that we need to create many roles as per each branches so that they can be linked with the security policy.
Is there any way to assign a dynamic query to a security policy ?

Did you found any solution for this. How can we achieve through code.