The answer to your question lies obviously in a script, for instance I have a script that orders layers from top to bottom with criteria of in point first on timeline, its almost what you request but not exactly. Maybe the script already exists somewhere, if not it sounds like an easy one to write, maybe you can request it at aescripts.com.
Jean