Mechanical and optical sorting systems